import { _decorator, Button, Tween, tween, UITransform, Widget } from 'cc';
import { Ab_DataTransfer_bA } from '../../../A-FRAME/A-LIB/lib.b.data';
import { Ab_BaseUI_bA } from '../../../A-FRAME/component/ui.base';
import Ab_Config_bA from '../../manager/config.manager';
import Ab_GameDC_bA from '../../manager/data.game.center';
import { Ab_GamePopup_bA } from './popup.game';
const { ccclass, property } = _decorator;

@ccclass('Ab_GameHomeUI_bA')
export class Ab_GameHomeUI_bA extends Ab_BaseUI_bA {

	private Ab_ui_top_bA: UITransform;
	private Ab_va_top_bA: abi.Ab_cc_bA.Ab_VecAssist_bA;

	protected Ab_initAfterOnLoad_bA(){
		this.Ab_ui_top_bA = this.node.getChildByName('top').getComponent(UITransform);
		this.Ab_va_top_bA = new abi.Ab_cc_bA.Ab_VecAssist_bA(this.Ab_ui_top_bA.node);
	}

	protected start(){
		let wgt = this.node.getComponent(Widget);
		if(wgt) wgt.updateAlignment();

		this.Ab_va_top_bA.Ab_getPosition_bA('Ab_center_bA', 'Ab_over_top_bA');
		this.Ab_ui_top_bA.node.setPosition(this.Ab_va_top_bA.Ab_vec_bA);

		let reg = Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Trigger_bA, 'Ab_LiveCommentsProgress_bA', ()=>{
			let [f, t] = Ab_GameDC_bA.Ab_Trigger_bA.Ab_LiveCommentsProgress_bA.split(',').map(v=>parseInt(v));
			let p = f/t;
			if(p>=1){
				Ab_DataTransfer_bA.Ab_cancel_bA(reg);
				this.node.active = false;
			}
		}, false);
	}

	protected Ab__click_event__bA: { [name: string]: (this: Ab_GameHomeUI_bA, button: Button) => void; } = {
		setting(btn){
			btn.interactable = false;
			Ab_GamePopup_bA.Ab_Setting_bA().then(()=>btn.interactable = true);
		}
	};

	protected Ab_listening_bA(){
		let list = [
			Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Trigger_bA, 'Ab_UIHome_bA', (_, show)=>{
				if(_==show) return void 0;
				if(show) this.Ab_enter_bA();
				else this.Ab_leave_bA();
			}, false)
		];
		return list;
	}

	private Ab_enterAfter_bA(){
	}

	private Ab_enter_bA(duration?: number){
		this.node.active = true;
		duration = duration ?? 0.5;

		this.Ab_va_top_bA.Ab_getPosition_bA('Ab_center_bA', 'Ab_top_bA');
		if(abi.Ab_cc_bA.Ab_is_long_screen_bA) this.Ab_va_top_bA.Ab_vec_bA.add3f(0, -100, 0);

		Tween.stopAllByTarget(this.Ab_ui_top_bA.node);
		tween(this.Ab_ui_top_bA.node)
		.to(duration, {position: this.Ab_va_top_bA.Ab_vec_bA}, {easing: 'cubicOut'})
		.call(()=>this.Ab_enterAfter_bA())
		.start();
	}

	private Ab_leave_bA(duration?: number){
		duration = duration ?? 0.5;

		this.Ab_va_top_bA.Ab_getPosition_bA('Ab_center_bA', 'Ab_over_top_bA');

		Tween.stopAllByTarget(this.Ab_ui_top_bA.node);
		tween(this.Ab_ui_top_bA.node)
		.to(duration, {position: this.Ab_va_top_bA.Ab_vec_bA}, {easing: 'cubicIn'})
		.call(()=>this.node.active = false)
		.start();

		if(Ab_GameDC_bA.Ab_User_bA.Ab_round_bA) Ab_GameDC_bA.Ab_Trigger_bA.Ab_UILuckyBox_bA = false;
	}
}

